package com.lxw.oa.controller.common;

import com.lxw.oa.controller.io.BaseTo;
import com.lxw.oa.service.DataOverviewService;
import com.lxw.oa.util.MenuTreeGridData;
import com.lxw.oa.util.TreeModal;
import com.lxw.oa.util.TreeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@EnableTransactionManagement
@RequestMapping("/data")
public class DataOverviewController {

    @Autowired
    private DataOverviewService dataOverviewService;

    @PostMapping("/getDataInfo")
    @ResponseBody
    public BaseTo getInformation(){
        int order1=0;
        int order2=0;
        List<Map<String,String>> list=dataOverviewService.getTableInfo();
        List<TreeModal> Root = TreeUtil.getChildModel(list,"","","table_schema",
                "","0",true);
        //循环根目录得到第一层
        for(TreeModal treeModal:Root){
            //第一层目录
            List<TreeModal> top1=TreeUtil.getChildModel(list,"table_schema",treeModal.getDataName(),
                    "table_syscomment","","1",false);
            //循环第一层目录得到第二层
            for(TreeModal treeModal1:top1){
                //第二层目录
                List<TreeModal> top2=TreeUtil.getChildModel(list,"table_syscomment",treeModal1.getDataName(),
                        "table_name","table_comment","2",false);
                //循环第二层目录得到第三层
                for(TreeModal treeModal2:top2){
                    //第三层目录
                    List<TreeModal> top3=TreeUtil.getChildModel(list,"table_name",treeModal2.getDataName(),
                            "column_name","column_comment","low",false);
                    treeModal2.setChild(top3);
                }
                treeModal1.setChild(top2);
            }
            treeModal.setChild(top1);
        }
        return new BaseTo(Root);
    }


}
